package cn.xawl.gulimall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lh
 * @date 2020/08/14 15:37:39
 **/
@Configuration
public class ESConfig {


    public static final RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//        builder.addHeader("Authorization", "Bearer " + TOKEN);
//        builder.setHttpAsyncResponseConsumerFactory(
//                new HttpAsyncResponseConsumerFactory
//                        .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }


    /**
     * 给容器中加入ES的client
     * @return RestHighLevelClient
     */
    @Bean
    public RestHighLevelClient esClient() {
        return new RestHighLevelClient(RestClient.builder(
                new HttpHost("192.168.56.7", 9200)
        ));
    }

}
